<?php

use Illuminate\Database\Seeder;
use App\Models\Topic;
use App\Models\User;
use App\Models\Category;
class TopicsTableSeeder extends Seeder
{
    public function run()
    {
        $faker = app(Faker\Generator::class);
        $category_ids = [1,2,3,4];
        $user_ids = User::all()->pluck('id')->toArray();
        $topics = factory(Topic::class)->times(20)->make()->each(function ($topic, $index)
            use ($faker,$category_ids,$user_ids)
        {
            $topic->user_id = $faker->randomElement($user_ids);
            $topic->category_id = $faker->randomElement($category_ids);
        });

        Topic::insert($topics->toArray());
    }

}

